<?php

namespace App\Http\Controllers\Video;

use App\Models\Video;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class VideoController extends Controller
{
    public function update(Request $request)
    {
        Video::where('id', $request->vid)->update([
            'title' => $request->title,
            'slug' => str_slug($request->title, '-'),
            'description' => $request->description,
            'visibility' => $request->visibility,
        ]);

        return response()->json(['status' => 'success']);
    }

    public function store(Request $request)
    {
        $vid = $request->user()->videos()->insertGetId([
            'title' => $request->title,
            'slug' => str_slug($request->title, '-'),
            'description' => $request->description,
            'visibility' => $request->visibility,
            'allow_comment' => false,
            'allow_votes' => false,
            'user_id' => auth()->id(),
            'status' => 1,
            'processed' => false,
            'video_filename' => $request->extension
        ]);
        return response()->json(['vid' => $vid]);
    }
}
